package com.east.controller;

import cn.hutool.http.ContentType;
import com.alibaba.excel.EasyExcel;
import com.east.dto.CustomerDTO;
import com.east.manager.CustomerManager;
import com.east.query.ClueQuery;
import com.east.query.CustomerQuery;
import com.east.result.Result;
import com.east.service.CustomerService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.checkerframework.checker.units.qual.C;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.net.URLEncoder;

@RestController
@RequestMapping("/api/customer/")
public class CustomerController {
    @Resource
    private CustomerManager customerManager;
    @Resource
    private CustomerService customerService;

    @PostMapping("clue2customer")
    public Result clue2customer(@RequestBody CustomerDTO customerDTO) {
        return customerManager.clue2customer(customerDTO);
    }

    @GetMapping("list")
    public Result list(
            @RequestParam(value = "currentPage", defaultValue = "1", required = false) Integer currentPage,
            @RequestParam(value = "pageSize", defaultValue = "8", required = false) Integer pageSize,
            @RequestParam(value = "fullName", required = false) String fullName
    ) {
        return customerService.list(currentPage, pageSize, fullName);
    }

    /**
     * 实现批量导出和选择导出到excel
     *
     * @param response
     * @param ids
     * @throws IOException
     */
    @GetMapping("all2excel")
    @PreAuthorize(value = "hasAuthority('customer:export')")
    public void all2excel(HttpServletResponse response,
                          @RequestParam(value = "ids", required = false) String ids) throws IOException {
        customerManager.all2excel(response, ids);
    }


    @GetMapping("info/{id}")
    public Result info(@PathVariable(value = "id") Integer id) throws IOException {
        return customerManager.info(id);
    }
    // @GetMapping("selected2excel")
    // @PreAuthorize(value = "hasAuthority('customer:export')")
    // public void selected2excel(HttpServletResponse response,
    //                            ) throws IOException {
    //     customerManager.selected2excel(response, ids);
    // }
}
